<template>
    <div class="exportFile">
        <a-table
                :columns="columns"
                :dataSource="data"
                :pagination="pagination"
                size="small"
                @change="deviceTableChange"
        >
            <template slot="button" slot-scope="text, record">
                <template  v-if="record.state==0">
                    <a-button @click="exportFile(record)" disabled="disabled">导出 </a-button>
                </template>
                <template  v-if="record.state==1">
                    <a-button @click="exportFile(record)">导出 </a-button>
                </template>
            </template>
        </a-table>
    </div>
</template>

<script>
    import PerConfig from '../../api/system/ParkApi'
    import CommonCons  from '../../utils/Constant'
    const columns = [
        {title: '文件名称', dataIndex: 'name', width: '25%',},
        {title: '导出状态', dataIndex: 'sate', width: '25%',},
        {title: '导出时间', dataIndex: 'time', width: '25%',},
        {title: '导出', dataIndex: 'export', width: '25%', scopedSlots: { customRender: 'button'},},
    ];
    const condition = {curr : 1, limit : 100};
    export default {
        name: "exportFile",
        mounted() {
            this.getFile(this.condition)
        },
        data() {
            return {
                columns,
                condition,
                data:[],
                pagination: {
                    showTotal: total => `共${total}条`,
                    total: 0,
                    defaultCurrent: 1,
                    showQuickJumper: true,
                    defaultPageSize: 100
                },
            };
        },
        methods: {
            //获取文件列表
            getFile(condition){
                let fileList=[];
                PerConfig.getFileList(condition).then(data=>{
                    if(data.code===2000){
                        this.pagination.total = data.data.total;
                        let list = data.data.list;
                        list.forEach(item=>{
                            fileList.push({key:item.id,name:item.name,sate:item.status==0?'文件生成中':'文件生成完成',time:item.createdTime,url:item.downloadUrl,state:item.status})
                        });
                        this.data=fileList
                    }
                }).catch(error=>{
                    console.log(error)
                })
            },
            //
            deviceTableChange(page){
                let condition = {curr : page.current, limit : page.defaultPageSize};
                this.getFile(condition)
            },
            exportFile(record){
                let url = encodeURI(CommonCons.QiNiuURL + '/' + record.url).replace(/#/g,'%23');
                window.open(url);
            },
        },
    }
</script>

<style scoped>
    /*.exportFile*/
</style>
